/**
 * 
 */
package org.hackystat.projecttrajectory.resource.summary;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import org.hackystat.project.ProjectException;
import org.hackystat.projecttrajectory.ProjectTrajectoryProperties;
import org.hackystat.projecttrajectory.client.ProjectTrajectoryClient;
import org.hackystat.projecttrajectory.client.ProjectTrajectoryException;
import org.hackystat.projecttrajectory.resource.summary.jaxb.ProjectSummary;
import org.hackystat.projecttrajectory.test.ProjectTrajectoryTestHelper;
import org.hackystat.sensorbase.client.SensorBaseClient;
import org.hackystat.sensorbase.client.SensorBaseClientException;
import org.hackystat.utilities.tstamp.Tstamp;
import org.junit.Test;

/**
 * Tests the Project Summary portion of the ProjectTrajectory REST API.
 * 
 * @author Cam Moore
 */
public class TestProjectSummaryRestApi extends ProjectTrajectoryTestHelper {

  /** The user for this test case. */
  private String user = "TestSummary@hackystat.org";

  /**
   * Test the summary of the Default project.
   */
  @Test
  public void testDefaultSummary() {
    try {
      ProjectTrajectoryProperties properties = ProjectTrajectoryProperties.getInstance();
      properties.setTestProperties();
      // Connect to the sensorbase and register the ProjectSummary user.
      SensorBaseClient.registerUser(getSensorBaseHostName(), user);
      ProjectTrajectoryClient client = new ProjectTrajectoryClient(getProjectTrajectoryHostName(),
          user, user);
      client.authenticate();
      ProjectSummary summary = client.getProjectSummary(user, "Default", Tstamp
          .makeTimestamp("2007-04-30"));
      assertEquals("Shouldn't have any time", 0, summary.getProjectData().getTotalEffort()
          .intValue());
      assertEquals("Shouldn't have any active days", 0, summary.getProjectData().getActiveDays()
          .intValue());
      assertEquals("Shouldn't have any size", 0, summary.getProjectData().getTotalSize()
          .intValue());
    } catch (ProjectException e) {
      fail("Could not instantiate ProjectTrajectoryProperties");
    } catch (ProjectTrajectoryException e) {
      e.printStackTrace();
      fail("Could not authenticate");
    } catch (SensorBaseClientException e) {
      e.printStackTrace();
      fail("Could not register " + user);
    } catch (Exception e) {
      e.printStackTrace();
      fail("Could not create time stamp.");
    }
  }
}
